package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TBasePallet;
import com.ruoyi.system.service.ITBasePalletService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * tuopanController
 *
 * @author ruoyi
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/system/warehouse/pallet")
public class TBasePalletController extends BaseController
{
    @Autowired
    private ITBasePalletService tBasePalletService;

    /**
     * 查询tuopan列表
     */
    @PreAuthorize("@ss.hasPermi('system:pallet:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBasePallet tBasePallet)
    {
        startPage();
        List<TBasePallet> list = tBasePalletService.selectTBasePalletList(tBasePallet);
        return getDataTable(list);
    }

    /**
     * 导出tuopan列表
     */
    @PreAuthorize("@ss.hasPermi('system:pallet:export')")
    @Log(title = "导出托盘数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBasePallet tBasePallet)
    {
        List<TBasePallet> list = tBasePalletService.selectTBasePalletList(tBasePallet);
        ExcelUtil<TBasePallet> util = new ExcelUtil<TBasePallet>(TBasePallet.class);
        util.exportExcel(response, list, "tuopan数据");
    }

    /**
     * 获取tuopan详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pallet:query')")
    @GetMapping(value = "/{palletId}")
    public AjaxResult getInfo(@PathVariable("palletId") String palletId)
    {
        return success(tBasePalletService.selectTBasePalletByPalletId(palletId));
    }


    /**
     * 新增tuopan
     */
    @PreAuthorize("@ss.hasPermi('system:pallet:add')")
    @Log(title = "新增托盘", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBasePallet tBasePallet)
    {
        return toAjax(tBasePalletService.insertTBasePallet(tBasePallet));
    }

    /**
     * 修改tuopan
     */
    @PreAuthorize("@ss.hasPermi('system:pallet:edit')")
    @Log(title = "修改托盘", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBasePallet tBasePallet)
    {
        return toAjax(tBasePalletService.updateTBasePallet(tBasePallet));
    }

    /**
     * 删除tuopan
     */
    @PreAuthorize("@ss.hasPermi('system:pallet:remove')")
    @Log(title = "删除托盘", businessType = BusinessType.DELETE)
    @DeleteMapping("/{palletIds}")
    public AjaxResult remove(@PathVariable String[] palletIds)
    {
        return toAjax(tBasePalletService.deleteTBasePalletByPalletIds(palletIds));
    }
}
